package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysRoleMapper;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName: SysRoleServiceImpl
 * @Package: com.atguigu.spzx.manager.service.impl
 * @Description
 * @Author 孤妤
 * @Date: 2023/12/4 20:34
 */
@Service
@Transactional
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Override
    @Transactional(readOnly = true)
    public PageInfo<SysRole> findByPage(Integer pageNum, Integer pageSize, SysRoleDto sysRoleDto) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysRole> sysRoles = sysRoleMapper.selectByPage(sysRoleDto);
        PageInfo<SysRole> sysRolePageInfo = new PageInfo<>(sysRoles);
        return sysRolePageInfo;
    }

    @Override
    @Transactional(readOnly = true)
    public SysRole findById(Integer id) {
        return sysRoleMapper.selectById(id);
    }

    @Override
    public void addSysRole(SysRole sysRole) {
        sysRoleMapper.insertSysRole(sysRole);
    }

    @Override
    public void removeById(Integer id) {
        sysRoleMapper.deleteById(id);
    }

    @Override
    public void changeSysRole(SysRole sysRole) {
        sysRoleMapper.updateSysRole(sysRole);
    }
}
